<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
	
    <link rel="stylesheet" type="text/css"
    href="<c:url value="/static/css2/css/common.css"/>">
    <link rel="stylesheet" type="text/css"
    href="<c:url value="/static/css2/fonts/iconfont.css"/>">
    <link rel="stylesheet" type="text/css"
    href="<c:url value="/static/css2/css/style.css"/>">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
    href="<c:url value="/static/css/jquery.ui.css"/>" />
	
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
			src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/js/LodopFuncs.js"/>"></script>

<script type="text/javascript"
            src="<c:url value="/static/js/footer.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/jsp/ordermanage/customDetailedMaterIndexForSup.js"/>"></script>
<script type="text/javascript">
    var dataLeft;
    var xhrDelete;
	function initList(listDisplayEId) {
		$('#' + listDisplayEId).datagrid(
				{
					nowrap : false,
					striped : true,
					collapsible : true,
					remoteSort : true,
					notSelectByRow : false,
					toolbar : [
							],
					onLoadError : function() {
						$.messager.alert('错误', '获取数据失败，请与管理员联系！', 'error');
					},
					/* onClickRow :  function(rowIndex) {
						$(".myrad").prop("checked", false);
						$(".myrad").eq(rowIndex).prop("checked", true);
						$('#listDisplay').datagrid('beginEdit', rowIndex);
					}, */
					onClickCell: onClickCell,
					/* onLoadSuccess : function() {
                        var rows = $('#listDisplay')
                                .datagrid('getRows');
                        for (var i = 0; i < rows.length; i++) {
                            var rowIndex = $('#listDisplay').datagrid(
                                    'getRowIndex', rows[i]['ordSupMaterId']);
                            $('#listDisplay').datagrid('beginEdit',
                                    rowIndex);
                        }
                    }, */
					toolbar : [
                               {
                                   id : listDisplayEId + '_btn_del',
                                   text : '删除',
                                   iconCls : 'icon-cancel',
                                   handler : function() {
                                	   var row = $('#'+listDisplayEId).datagrid('getSelections');      
                                       if(row.length == 0){
                                           $.messager.alert('提示','请选择一条记录操作！','info');
                                           return;
                                       } else {
                                           $.messager.confirm('提示', '是否删除该条记录？', function(r){
                                               if (r){
                                                   deleteMater(row);
                                               }
                                           });
                                       }
                                   }
                               },
                               {
                                   id : listDisplayEId + '_btn_add',
                                   text : '临时加货',
                                   iconCls : 'icon-add',
                                   handler : function() {
                                       var rows = $('#listDisplay')
                                               .datagrid('getRows');
                                       if (rows.length == 0) {
                                           alert("请先选择客户并查询订单数据！");
                                       } else {
                                           var new_win = window
                                                   .open(
                                                           "<c:url value='/jsp/openIndexSun.jsp?url=/order/preUpdateSelectMater.do'/>"
                                                                   + "?ordId="
                                                                   + rows[0]['ordId']
                                                                   + "&supId=${supId }&buySupplier=1",
                                                           "sun",
                                                           "width=1200px,height=600px,status=no,scrollbars=yes");
                                           new_win.focus();
                                       }
                                   }
                               },
                               {
                                   id : listDisplayEId + '_btn_add',
                                   text : '改变材料',
                                   iconCls : 'icon-add',
                                   handler : function() {
                                	   //先检查订单
                                       if(!("${ordState }"== 3 || "${ordState }"== "21")){
                                           alert("订单已被发货不能操作！");
                                           return false;
                                       }
                                	   var row = $('#'+listDisplayEId).datagrid('getSelections');      
                                       if(row.length != 1){
                                           $.messager.alert('提示','请选择一条记录操作！','info');
                                           return;
                                       } else {
                                    	   addMaterRow();
                                       }
                                   }
                               },
                               {
                                   id : listDisplayEId + '_btn_search',
                                   text : '检索最后进货价格',
                                   iconCls : 'icon-search',
                                   handler : function() {
                                       searchMaterValue();
                                   }
                               },
                               {
                                   id : listDisplayEId + '_btn_search',
                                   text : '计算出货价格',
                                   iconCls : 'icon-search',
                                   handler : function() {
                                	   calculationMaterValue();
                                   }
                               },
                               {
                                   id : listDisplayEId + '_btn_search',
                                   text : '检索最后出货价格',
                                   iconCls : 'icon-search',
                                   handler : function() {
                                	   searchLastShipmentValue();
                                   }
                               },
                               /* {
                                   id : listDisplayEId + '_btn_search',
                                   text : '校验价格合理性',
                                   iconCls : 'icon-search',
                                   handler : function() {
                                       checkValue();
                                   }
                               }, */
                               /* {
                                   id : listDisplayEId + '_btn_search',
                                   text : '检索周期报价',
                                   iconCls : 'icon-search',
                                   handler : function() {
                                       checkCompanyPeriod();
                                   }
                               }, */
                               {
                                   id : listDisplayEId + '_btn_add',
                                   text : '导入数量和卖出价格',
                                   iconCls : 'icon-add',
                                   handler : function() {
                                	   updateMaterWeightAndValue();
                                   }
                               },
                               {
                                   id : listDisplayEId + '_btn_add',
                                   text : '预览对货单并打印',
                                   iconCls : 'icon-print',
                                   handler : function() {
                                       prn1_view_Check();
                                   }
                               },
                               {
                                   id : listDisplayEId + '_btn_add',
                                   text : '预览送货单并打印',
                                   iconCls : 'icon-print',
                                   handler : function() {
                                       prn1_view();
                                   }
                               }
                            ]
				}
		); 
	};
	function deleteMater(row){
        
        var dateone = '[ ';
        for(var i=0; i<row.length; i++){
            dateone = dateone+'{"ordId":"'+ row[i]['ordId']+'","ordMaterId":"'+ row[i]['ordMaterId'] +'","ordSupId":"'+ row[i]['ordSupId']+'"}';
            if(i != row.length-1){
                dateone = dateone+',';
            }
        }
        dateone = dateone + ']';

        var parameters = new Array();
        var parameter = {
        	    ordId : 1,
        	    ordMaterId: 2,
        	    ordSupId: 3
        	    }; 
        parameters.push(parameter);
        var dataOneJson =  JSON.stringify([{"ordId":"1","ordMaterId":"2","ordSupId":"3"},{"ordId":"2","ordMaterId":"4","ordSupId":"4"}]);
        var form = new FormData();
        form.append("jsonString", dateone); // 可以增加表单数据
        xhrDelete = new XMLHttpRequest();
        xhrDelete.onreadystatechange = xhrDelete_return;
        xhrDelete.open("post", '<c:url value='/order/deleteOrderSupperMaterList.do'/>', true);
        xhrDelete.send(form);
           
    }
	
    var editIndex = undefined;
    $.extend($.fn.datagrid.methods, {
        editCell: function(jq,param){
            return jq.each(function(){
            	//取得周期标记
                var periodValueFlag =  $("#listDisplay").datagrid('getData').rows[param.index]["periodValueFlag"];
            	
                var opts = $(this).datagrid('options');
                var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
                for(var i=0; i<fields.length; i++){
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor1 = col.editor;
                    if (fields[i] != param.field){
                        col.editor = null;
                    }
                    
                    //如果周期报价不能编辑
                    /* if( periodValueFlag ==1 && param.field == 'ordMaterValueRealUnit'){
                    	col.editor = null;
                    } */
                    
                }
                $(this).datagrid('beginEdit', param.index);
                for(var i=0; i<fields.length; i++){
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor = col.editor1;
                }
            });
        }
    });
    function endEditing(){
        if (editIndex == undefined){return true}
        if ($('#listDisplay').datagrid('validateRow', editIndex)){
            $('#listDisplay').datagrid('endEdit', editIndex);
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
	function onClickCell(index, field){
        if (endEditing()){
            $('#listDisplay').datagrid('selectRow', index)
                    .datagrid('editCell', {index:index,field:field});
            editIndex = index;
        }
    }
	
	$(document).ready(function() {
		initList('listDisplay');
		getSupName();
		document.getElementById('unitDiv').style.display = 'none';
	    document.getElementById('zzy2').style.display = 'none';

		
		
		$('#selectMaterUnit').click(function() {
            Loading.Hide();
            document.getElementById('unitDiv').style.display = 'none';
            $('#unitChangeForm').form('submit',
                    {
                        url:'<c:url value='/order/unitMaterChange.do'/>', //查询提交路径
                        onSubmit:function()//提交按钮相应函数
                            {
                        	    if(!isNumber(document.getElementById('ordMaterWeightReal').value)){
                        	    	 $.messager.alert("提示", "'数量请填写数字！", 'info');
                        	    	 return false;
                        	    }else if(document.getElementById('ordMaterWeightReal').value==0||document.getElementById('ordMaterWeightReal').value=='0'){
                                    $.messager.alert("提示", "'数量不能为0！", 'info');
                                    return false;
                                }else{
                                    return $('#unitChangeForm').form('validate');
                                }
                            },
                        success:function(data){
                            data = eval( "("+data+")" );
                            if(data.success){
                                $.messager.alert("提示", "'转换成功！", 'info');
                                $('#listDisplay').datagrid('reload');
                            }else{
                                $.messager.alert("提示", "'转换失败请联系管理员！", 'info');
                            }
                        },
                        error:function(){
                            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                            return;
                        }
                    }
            );
            
        });
        $('#noselectMaterUnit').click(function() {
        	Loading.Hide();
            document.getElementById('unitDiv').style.display = 'none';
        });
	});
	//检索最后一次出货价格
	function searchLastShipmentValue(){
		var rows = $('#listDisplay').datagrid('getSelections');
		if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
            for (var i = 0; i < rows.length; i++) {
                var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                        rows[i]['ordSupMaterId']);
                $('#listDisplay').datagrid('endEdit', rowIndex);
                if(rows[i]['periodValueFlag'] ==1){
                    continue;
                }
                rows[i]['ordMaterValueRealUnit'] = getLastShipmentValue(rows[i]['ordMaterId'],rows[i]['ordCustId']);
                rows[i]['ordMaterValueReal'] = decimal(rows[i]['ordMaterValueRealUnit']*rows[i]['ordMaterWeightReal'],2);
                //alert(i);
                $('#listDisplay').datagrid('refreshRow', rowIndex);
                //alert(rowIndex);
                //$('#listDisplay').datagrid('beginEdit', rowIndex);
            }
        }
	}
	
	function getLastShipmentValue(materId,ordCustId) {
	    var returnString;
	    $.ajax({
	        async : false,
	        url : "<c:url value='/materSup/getLastShipmentValue.do'/>" + "?materId=" + materId +"&shopId=" + ordCustId,
	        type : "post",
	        success : function(data) {
	            if (typeof (data) == 'string') {
	                data = JSON.parse(data);
	            }
	            returnString = data.materValue;
	        }
	    });
	    return returnString;
    }
	//检索周期报价
	function checkCompanyPeriod(){
		 var rows = $('#listDisplay').datagrid('getRows');
		 for (var i = 0; i < rows.length; i++) {
             var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                     rows[i]['ordSupMaterId']);
             $('#listDisplay').datagrid('endEdit', rowIndex);
             rows[i]['ordMaterValueRealUnit'] = getCompanyPeriodValue(rows[i]['ordMaterId'],rows[i]['ordCustId']);
             rows[i]['ordMaterValueReal'] = decimal(rows[i]['ordMaterValueRealUnit']*rows[i]['ordMaterWeightReal'],2);
             $('#listDisplay').datagrid('refreshRow', rowIndex);
             $('#listDisplay').datagrid('beginEdit', rowIndex);
         } 
	            
	        
	}
	function getCompanyPeriodValue(materId,ordCustId) {
        var returnString;
        $.ajax({
            async : false,
            url : "<c:url value='/quotationCompany/getCompanyPeriodValue.do'/>"
                    + "?materId=" + materId +"&shopId="+ordCustId,
            type : "post",
            success : function(data) {
                if (typeof (data) == 'string') {
                    data = JSON.parse(data);
                }
                returnString = data.materCompanyPeriodValue;
            }
        });
        return returnString;
    }
	//检索材料进货价格
	function searchMaterValue() {
        var rows = $('#listDisplay').datagrid('getSelections');
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
            for (var i = 0; i < rows.length; i++) {
                var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                	    rows[i]['ordSupMaterId']);
                $('#listDisplay').datagrid('endEdit', rowIndex);
                rows[i]['ordMaterValueRealCostUnit'] = getMaterValueCost(rows[i]['ordMaterId']);
                rows[i]['ordMaterValueRealCost'] = decimal(rows[i]['ordMaterValueRealCostUnit']*rows[i]['ordMaterWeightReal'],2);
                $('#listDisplay').datagrid('refreshRow', rowIndex);
                //alert(rowIndex);
                //$('#listDisplay').datagrid('beginEdit', rowIndex);
            }
        }
    }
    function getMaterValueCost(materId) {
        var returnString;
        $.ajax({
            async : false,
            url : "<c:url value='/supplier/getMaterValueCostByMaterId.do'/>"
                    + "?materId=" + materId,
            type : "post",
            success : function(data) {
                if (typeof (data) == 'string') {
                    data = JSON.parse(data);
                }
                returnString = data.materValueCost;
            }
        });
        return returnString;
    }
    //实际价格计算
    function calculationMaterValue(){
    	 var rows = $('#listDisplay').datagrid('getSelections');
    	 if(rows.length == 0){
             $.messager.alert('提示','请选择一条记录操作！','info');
             return;
         }  else {
             for (var i = 0; i < rows.length; i++) {
                var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                     rows[i]['ordSupMaterId']);
                $('#listDisplay').datagrid('endEdit', rowIndex);
                if(rows[i]['periodValueFlag'] ==1){
                	continue;
                }
                rows[i]['ordMaterValueRealUnit'] = getMaterValueReal(rows[i]['ordMaterId'],rows[i]['ordMaterValueRealCostUnit'],rows[i]['ordCustId']);
                //修改总价格
                rows[i]['ordMaterValueReal'] = decimal(rows[i]['ordMaterValueRealUnit']*rows[i]['ordMaterWeightReal'],2);
                $('#listDisplay').datagrid('refreshRow', rowIndex);
                //$('#listDisplay').datagrid('beginEdit', rowIndex);
             }
         }
    }
    function getMaterValueReal(materId,materValueCost,ordCustId) {
        var returnString;
        $.ajax({
            async : false,
            url : "<c:url value='/supplier/getMaterValueRealByMaterId.do'/>"
                    + "?materId=" + materId+"&materValueCost=" + materValueCost+"&shopId="+ordCustId,
            type : "post",
            success : function(data) {
                if (typeof (data) == 'string') {
                    data = JSON.parse(data);
                }
                returnString = data.materValueReal;
            }
        });
        return returnString;
    }
	function addMater(){
			$('#AddFoodForm').form('submit',
			{
				url:'<c:url value='/order/commitMaterOrderReal.do'/>', //查询提交路径
				onSubmit:function()//提交按钮相应函数
				{
					return $('#AddFoodForm').form('validate');
				},
				success:function(data){
					data = eval( "("+data+")" );
	       			if(data.success){
	       				$.messager.alert("提示", "提交成功！", 'info');
						$('#listDisplay').datagrid('reload');
    				}else{
    					var tmsg= ""
    					if(data.msg == "msg005"){
    	       				$.messager.alert("提示", "状态不正确，请确认材料订单状态是否为品级确认完毕", 'warning');
    					}else if(data.msg == "msg006"){
    						$.messager.alert("提示", "今日菜品价格还没有录入，请等待或联系采购部门。", 'warning');
    					}else if(data.msg == "msg003"){
                            $.messager.alert("提示", "已经提交过实际价格。", 'warning');
                        }
    				}
				},
				error:function(){
					$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
					return;
				}
			});
			
		}
	// 颜色
    function cellStylerTrue(value, row, index) {
        return 'background-color:#00BB00;';
    }
	
    function cellStylerLeaveMessage(value, row, index) {
        if (row['leaveMessage'] != '') {
            return 'background-color:#CCFFCC;';
        }
    }
    function cellStyler(value, row, index) {
        if (row['periodValueFlag'] == '1') {
            return 'background-color:red;';
        } else {
            return 'background-color:#00BB00;';
        }
    }
    function getSupName() {
        $.ajax({
            async : false,
            url : "<c:url value='/supplier/getSupPoByUserId.do'/>",
            type : "post",
            success : function(data) {
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                document.getElementById('supName').value = data.supName;
                document.getElementById('ordSupId').value = data.supId;
            }
        });
    }
    function prn1_view_Check(){
    	LODOP = getLodop();
        LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_整页表格");
        LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
        //alert(document.getElementById("listDisplay"));
        //LODOP.ADD_PRINT_TABLE("2%","1%","96%","98%",document.getElementById("listDisplay").innerHTML);
        var tableString = getPrnStrcheck();
        //LODOP.ADD_PRINT_IMAGE(0,0,'100%','100%',"<img  border='0' style='z-index: -1; position: absolute;' src='../images/seal/caigouzhang2.png'/>");
        LODOP.ADD_PRINT_TABLE(5, 5, '99%', '94%', tableString);
        LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 800, 600, "");
        LODOP.PREVIEW();
    }
    
    function getPrnStrcheck() {
        var rows = $('#listDisplay').datagrid('getRows');
        var date = rows[0]['ordDate'];
        var tableStr;
        tableStr = "<table style='border-collapse: collapse; border-style:solid;border: none;'>"
        //设置公司标题
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='2' align='right' style='font-size:15px;border-style:solid;border-width:0px;height:30px'>"
                + "日期" + date + "</td>"
                + "<td colspan='3' align='right' style='font-size:20px;border-style:solid;border-width:0px;height:30px'>"
                + document.getElementById('supName').value + "</td>"
                + "<td colspan='5' align='center' style='font-size:15px;border-style:solid;border-width:0px;height:30px'>"
                + "订单号：${ordId }" + "</td>";

        tableStr = tableStr + "</tr>";

        //设置列表属性
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:6%'>序号</td>";
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:16%'>店名</td>";
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:15%'>材料名</td>";
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:10%'>种类</td>";
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:13%'>规格</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;width:10%'>需求数量</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;width:10%'>实际数量</td>";
        tableStr = tableStr
                + "<td align='center' style='border-style:solid;border-width:1px;width:8%'>单位</td>";
        tableStr = tableStr
                + "<td align='center' style='border-style:solid;border-width:1px;width:18%'>留言</td>";
        tableStr = tableStr + "</tr>";
        var materValueAllList = 0;
        var date;
        for (var i = 0; i < rows.length; i++) {
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + (i + 1) + "</td>";
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + rows[i]['ordCustName'] + "</td>";
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + rows[i]['ordMaterName'] + "</td>";
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + rows[i]['materType'] + "</td>";
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + rows[i]['specifications'] + "</td>";
            tableStr = tableStr
                    + "<td align='right' style='border-style:solid;border-width:1px;'>"
                    + rows[i]['ordMaterWeight'] + "</td>";
            tableStr = tableStr
                    + "<td align='right' style='border-style:solid;border-width:1px;'>"
                    + "" + "</td>";
            tableStr = tableStr
                    + "<td align='center' style='border-style:solid;border-width:1px;'>"
                    + rows[i]['unit'] + "</td>";
            tableStr = tableStr
                    + "<td align='center' style='border-style:solid;border-width:1px;'>"
                    + rows[i]['leaveMessage'] + "</td>";
            tableStr = tableStr + "</tr>";
            materValueAllList = decimal(accAdd(materValueAllList,rows[i]['ordMaterValueReal']), 2);
            date=rows[i]['ordDate'];
        }
        tableStr = tableStr + "</table>";
        return tableStr;
    }
    function prn1_view() {
    	if(check()){
    		LODOP = getLodop();
            LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_整页表格");
            LODOP.SET_PRINT_PAGESIZE(1,2100,2770,""); ;
            //alert(document.getElementById("listDisplay"));
            //LODOP.ADD_PRINT_TABLE("2%","1%","96%","98%",document.getElementById("listDisplay").innerHTML);
            //var tableString = getPrnStr("${shopPo.unitFlag }");
            var tableString = "";
            if(2=="${shopPo.deliveryClass }"){
            	var rows = $('#listDisplay').datagrid('getRows');
                if(rows.length <=30){
                    tableString = getPrnStr2();
                    LODOP.ADD_PRINT_TABLE(3, 5, '97%', '94%', tableString);
                } else {
                    tableString  = getPrnStrForWujing1new();
                    LODOP.ADD_PRINT_TABLE(5, 5, '97%', '94%', tableString);
                    var tableString2 = getPrnStrForWujing2new();
                    LODOP.ADD_PRINT_TABLE('50%', 5, '97%', '94%', tableString2);
                }
            }else if(1=="${shopPo.deliveryClass }"){
            	tableString = getPrnStr1("${shopPo.unitFlag }");
                LODOP.ADD_PRINT_TABLE(3, 80, '80%', "BottomMargin:5%", tableString);
            }else{
                tableString = getPrnStr("${shopPo.unitFlag }");
                LODOP.ADD_PRINT_TABLE(3, 5, '95%', "BottomMargin:5%", tableString);
            }
            //LODOP.ADD_PRINT_IMAGE(0,0,'100%','100%',"<img  border='0' style='z-index: -1; position: absolute;' src='../images/seal/caigouzhang2.png'/>");
            LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 800, 600, "");
            LODOP.PREVIEW();
            deal();
    	}
    }
    function check(){
    	//先检查订单
    	/* if(!("${ordState }"== 3 || "${ordState }"== "21")){
    		alert("订单已被发货不能打印！");
    		return false;
    	} */
    	var rows = $('#listDisplay').datagrid('getRows');
        for (var i = 0; i < rows.length; i++) {
            var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                    rows[i]['ordSupMaterId']);
            $('#listDisplay').datagrid('endEdit', rowIndex);
            if (!isNumber(rows[i]['ordMaterValueRealUnit'])
                    || !isNumber(rows[i]['ordMaterWeightReal'])) {
                $.messager.alert("提示", "'" + rows[i]['ordMaterName']
                        + "'金额和数量请填写数字！", 'info');
                //beginEditList(rows, '#listDisplay', 'ordSupMaterId');
                return false;
            }else if(rows[i]['ordMaterValueRealUnit']==0||rows[i]['ordMaterValueRealUnit']=="0.00"){
                $.messager.alert("提示", "'" + rows[i]['ordMaterName'] + "'送货单价不能为0！", 'info');
                //beginEditList(rows, '#listDisplay', 'ordSupMaterId');
                return false;
            }else if(rows[i]['ordMaterWeightReal']==0||rows[i]['ordMaterWeightReal']=="0.00"){
                $.messager.alert("提示", "'" + rows[i]['ordMaterName'] + "'实际送货数量不能0！", 'info');
                //beginEditList(rows, '#listDisplay', 'ordSupMaterId');
                return false;
            }else{
                //修改总价格
                rows[i]['ordMaterValueReal'] = decimal(rows[i]['ordMaterValueRealUnit']*rows[i]['ordMaterWeightReal'],2);
                $('#listDisplay').datagrid('refreshRow', i);
                //beginEditList(rows, '#listDisplay', 'ordSupMaterId');
            }
            
            
            //校验价格
            /* if(!checkMaterSale(rows[i]['ordMaterId'],rows[i]['ordMaterValueRealUnit'])){
                //beginEditList(rows, '#listDisplay', 'ordSupMaterId');
                return ;
            } */
            //校验是否有单位没有转换
            if(!checkMaterUnitChange(rows[i]['ordMaterId'])){
                //beginEditList(rows, '#listDisplay', 'ordSupMaterId');
                return ;
            }
        }
        return true;
    }
    function beginEditList(rows, list, id) {
        for (var i = 0; i < rows.length; i++) {
            var rowIndex = $(list).datagrid('getRowIndex', rows[i][id]);
            $(list).datagrid('beginEdit', rowIndex);
        }
    }
    //发货
    function updateState(){
        var rows = $('#listDisplay').datagrid('getRows');

        var str = "ordId="+"${ordId }"+"&ordCustId="+rows[0]['ordCustId'] +"&ordSupId="+"${supId }"+"&ordDate="+rows[0]['ordDate'];    

    	
    	$.ajax({type:'post',url:"<c:url value='/supporder/sendOrderSupplier.do'/>"+"?"+str,dataType:"json",//设置查询参数及提交路径
            success:function(data){
                if(data.success){
                }else{
                    $.messager.alert("提示", data.msg, 'warning');
                }
            },
            error:function(){
            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });
    };
    
    var xhr;
    function deal() {

        var rows = $('#listDisplay').datagrid('getRows');
       
        //生成json数据
        var turnoverList = new Array();
        var jsonFater;

        for (var i = 0; i < rows.length; i++) {
        	
            var jsonSun = "{materId:'" + rows[i]['ordMaterId'] + "',materLevel:'"
                    + rows[i]['ordMaterLevel'] + "',materWeight:'"
                    + rows[i]['ordMaterWeightReal'] 
                    + "',materValue:'" + rows[i]['ordMaterValueRealUnit'] 
                    + "',materValueUndressed:'" + rows[i]['ordMaterValueRealCostUnit']
                    + "',date:'"
                    + rows[i]['ordDate'] + "'}";
            turnoverList.push(jsonSun);
        }
        jsonFater = JSON.stringify(turnoverList);
        $("#materJson").attr("value", jsonFater);
        var form = new FormData();
        //ajax 提交表单数据
        form.append("date", rows[0]['ordDate']); // 可以增加表单数据
        form.append("custId", rows[0]['ordCustId']); // 可以增加表单数据
        form.append("ordId", '${ordId }'); // 可以增加表单数据
        form.append("materJson", jsonFater); // 可以增加表单数据
        // XMLHttpRequest 对象
        xhr = new XMLHttpRequest();
        
        xhr.onreadystatechange = xhr_return;
        xhr.open("post", '<c:url value='/supplier/importSupMaterValueForWeb.do'/>', true);
        xhr.send(form);
    }
    function xhr_return(){
        if (xhr.readyState == 4) {// 4 = "loaded"
            if (xhr.status == 200) {// 200 = OK
                var data;
                data = xhr.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                if(data.success){
                	//updateState();
                }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    
    function getPrnStr( unitFlag ) {
        var rows = $('#listDisplay').datagrid('getRows');

        var tableStr;
        tableStr = "<table  style='border-collapse: collapse; border: 2px solid black;'>"
        //设置公司标题
        tableStr = tableStr + "<thead>";

        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='9' align='center' style='font-size:20px;border-style:solid;border-width:2px;height:30px;border-right-width:0px'>"
                + document.getElementById('supName').value + "送货单</td>";

        tableStr = tableStr + "</tr>";
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='3' align='left' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-top-width: 0px;'>收货单位："+rows[0]['ordCustName']+"</td>"
                + "<td colspan='3' align='right' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-left-width:0px;border-top-width: 0px;'>订单号：${ordId }</td>"
                + "<td colspan='3' align='right' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-left-width:0px;border-top-width: 0px;'>送货日期:"
                + rows[0]['ordDate']; + "</td>";
        tableStr = tableStr + "</tr>";
        //设置列表属性
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:6%'>序号</td>";
        /*  tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:16%'>店名</td>"; */
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:14%'>种类</td>";
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:19%'>材料名</td>";
        tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:13%'>规格</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;width:10%'>需求数量</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;width:10%'>实际数量</td>";
        tableStr = tableStr
                + "<td align='center' style='border-style:solid;border-width:1px;width:8%'>单位</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;width:9%'>单价</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;width:9%'>总价</td>";
        tableStr = tableStr + "</tr>";
        tableStr = tableStr + "</thead>";
        var materValueAllList = 0;
        for (var i = 0; i < rows.length; i++) {
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + (i + 1) + "</td>";
            /* tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + rows[i]['ordCustName'] + "</td>"; */
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + rows[i]['materType'] + "</td>";
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + rows[i]['ordMaterName'] + "</td>";
            
            tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + rows[i]['specifications'] + "</td>";
                    
            if(unitFlag && rows[i]['unit']=='斤'){
                tableStr = tableStr
                 + "<td align='right' style='border-style:solid;border-width:1px;'>"
                 + decimal(rows[i]['ordMaterWeight']*0.5,2) + "</td>";
                tableStr = tableStr
                 + "<td align='right' style='border-style:solid;border-width:1px;'>"
                 + decimal(rows[i]['ordMaterWeightReal']*0.5,2) + "</td>";
                tableStr = tableStr
                 + "<td align='center' style='border-style:solid;border-width:1px;'>"
                 + "公斤" + "</td>";
                tableStr = tableStr
                 + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                 + decimal(rows[i]['ordMaterValueRealUnit']*2,2) + "</td>";
            }else{
            	tableStr = tableStr
                 + "<td align='right' style='border-style:solid;border-width:1px;'>"
                 + rows[i]['ordMaterWeight'] + "</td>";
                tableStr = tableStr
                 + "<td align='right' style='border-style:solid;border-width:1px;'>"
                 + rows[i]['ordMaterWeightReal'] + "</td>";
                tableStr = tableStr
                 + "<td align='center' style='border-style:solid;border-width:1px;'>"
                 + rows[i]['unit'] + "</td>";
                tableStr = tableStr
                 + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                 + rows[i]['ordMaterValueRealUnit'] + "</td>";
            }
            tableStr = tableStr
                    + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                    + rows[i]['ordMaterValueReal'] + "</td>";
            tableStr = tableStr + "</tr>";
            materValueAllList = decimal(accAdd(materValueAllList,rows[i]['ordMaterValueReal']), 2);
        }
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='7' align='left' style='border-style:solid;border-width:1px;'>送货人：___________ 接收人：___________ 审核人：___________ </td>";
        tableStr = tableStr
                + "<td colspan='1' align='right' style='border-style:solid;border-width:1px;'>合计:</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                + materValueAllList + "</td>";
        tableStr = tableStr + "</tr>";
        
        
        
        tableStr = tableStr + "<tfoot>";
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='9' align='right' style='font-size:15px;border-style:solid;border-width:0px;height:20px;'><font size='1'><span tdata='pageNO'>第##页</span>/<span tdata='pageCount'>共##页</span></font></td>"
                 + "</td>";
        tableStr = tableStr + "</tr>";
        tableStr = tableStr + "</tfoot>";
        tableStr = tableStr + "</table>";

        return tableStr;
    }
    
    function getPrnStr1( unitFlag ) {
        var rows = $('#listDisplay').datagrid('getRows');

        var tableStr;
        tableStr = "<table  style='border-collapse: collapse; border: 2px solid black;'>"
        //设置公司标题
        tableStr = tableStr + "<thead>";

        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='8' align='center' style='font-size:20px;border-style:solid;border-width:2px;height:30px;border-right-width:0px'>"
                + document.getElementById('supName').value + "送货单</td>";

        tableStr = tableStr + "</tr>";
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='3' align='left' style='font-size:12px;height:12px;border-style:solid;border-width:2px;border-right-width:0px;border-top-width: 0px;'>收货单位："+rows[0]['ordCustName']+"</td>"
                + "<td colspan='2' align='right' style='font-size:12px;height:12px;border-style:solid;border-width:2px;border-right-width:0px;border-left-width:0px;border-top-width: 0px;'>订单号：${ordId }</td>"
                + "<td colspan='3' align='right' style='font-size:12px;height:12px;border-style:solid;border-width:2px;border-left-width:0px;border-top-width: 0px;'>送货日期:"
                + rows[0]['ordDate']; + "</td>";
        tableStr = tableStr + "</tr>";

        //设置列表属性
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td style='font-size:12px;height:12px;border-style:solid;border-width:1px;width:6%'>序号</td>";
        /*  tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:16%'>店名</td>"; */
        /* tableStr = tableStr
                + "<td style='border-style:solid;border-width:1px;width:14%'>种类</td>"; */
        tableStr = tableStr
                + "<td style='font-size:12px;height:12px;border-style:solid;border-width:1px;width:19%'>材料名</td>";
        tableStr = tableStr
                + "<td style='font-size:12px;height:12px;border-style:solid;border-width:1px;width:13%'>规格</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;width:10%'>需求数量</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;width:10%'>实际数量</td>";
        tableStr = tableStr
                + "<td align='center' style='font-size:12px;height:12px;border-style:solid;border-width:1px;width:8%'>单位</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;width:9%'>单价</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;width:9%'>总价</td>";
        tableStr = tableStr + "</tr>";
        tableStr = tableStr + "</thead>";
        var materValueAllList = 0;
        for (var i = 0; i < rows.length; i++) {
        	
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                    + (i + 1) + "</td>";
            tableStr = tableStr
                    + "<td style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                    + rows[i]['ordMaterName'] + "</td>";
            
            tableStr = tableStr
                    + "<td style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                    + rows[i]['specifications'] + "</td>";
                    
            if(unitFlag && rows[i]['unit']=='斤'){
                tableStr = tableStr
                 + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                 + decimal(rows[i]['ordMaterWeight']*0.5,2) + "</td>";
                tableStr = tableStr
                 + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                 + decimal(rows[i]['ordMaterWeightReal']*0.5,2) + "</td>";
                tableStr = tableStr
                 + "<td align='center' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                 + "公斤" + "</td>";
                tableStr = tableStr
                 + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>￥"
                 + decimal(rows[i]['ordMaterValueRealUnit']*2,2) + "</td>";
            }else{
                tableStr = tableStr
                 + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                 + rows[i]['ordMaterWeight'] + "</td>";
                tableStr = tableStr
                 + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                 + rows[i]['ordMaterWeightReal'] + "</td>";
                tableStr = tableStr
                 + "<td align='center' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>"
                 + rows[i]['unit'] + "</td>";
                tableStr = tableStr
                 + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>￥"
                 + rows[i]['ordMaterValueRealUnit'] + "</td>";
            }
            tableStr = tableStr
                    + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>￥"
                    + rows[i]['ordMaterValueReal'] + "</td>";
            tableStr = tableStr + "</tr>";
            materValueAllList = decimal(accAdd(materValueAllList,rows[i]['ordMaterValueReal']), 2);
        }
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='6' align='left' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>送货人：__________ 接收人：__________ 审核人：__________ </td>";
        tableStr = tableStr
                + "<td colspan='1' align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>合计:</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:12px;height:12px;border-style:solid;border-width:1px;'>￥"
                + materValueAllList + "</td>";
        tableStr = tableStr + "</tr>";
        
        tableStr = tableStr + "<tfoot>";
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='8' align='right' style='font-size:12px;height:12px;border-style:solid;border-width:0px;'><font size='1'><span tdata='pageNO'>第##页</span>/<span tdata='pageCount'>共##页</span></font></td>"
                 + "</td>";
        tableStr = tableStr + "</tr>";
        tableStr = tableStr + "</tfoot>";
        tableStr = tableStr + "</table>";

        return tableStr;
    }
    
    function getPrnStr2() {
        var xuhao1,xuhao2;
        var rows = $('#listDisplay').datagrid('getRows');
        xuhao1=1;
        if(rows.length%2==0){
        	xuhao2=rows.length/2+1;
        }else{
        	xuhao2=Math.round(rows.length/2)+1;
        }
        
        var tableStr;
        tableStr = "<table  style='border-collapse: collapse; border: 2px solid black;'>"
        //设置公司标题
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='12' align='center' style='font-size:22px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-bottom-width: 0px;'>"
                + document.getElementById('supName').value + "送货单</td>";

        tableStr = tableStr + "</tr>";
        
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='6' align='left' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-top-width: 0px;'>收货单位："+rows[0]['ordCustName']+"</td>"
                + "<td colspan='3' align='right' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-left-width:0px;border-top-width: 0px;'>订单号：${ordId }</td>"
                + "<td colspan='3' align='right' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-left-width:0px;border-top-width: 0px;'>送货日期:"
                + rows[0]['ordDate']; + "</td>";
        tableStr = tableStr + "</tr>";

        //设置列表属性
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;width:4%'>号</td>";
        /* tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;width:9%'>种类</td>"; */
        tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;width:12%'>材料名</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:5%'>数量</td>";
        tableStr = tableStr
                + "<td align='center' style='font-size:14px;border-style:solid;border-width:1px;width:6%'>单位</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:7%'>单价</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:8%'>合计</td>";
        tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;width:4%'>号</td>";
        /* tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;width:9%'>种类</td>"; */
        tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;width:12%'>材料名</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:5%'>数量</td>";
        tableStr = tableStr
                + "<td align='center' style='font-size:14px;border-style:solid;border-width:1px;width:6%'>单位</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:7%'>单价</td>";
        tableStr = tableStr
                + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:8%'>合计</td>";
        tableStr = tableStr + "</tr>";
        var materValueAllList = 0;
        for (var i = 0; i < rows.length; i++) {
        	
        	if(i%2==0){
        		tableStr = tableStr + "<tr>";
        	}
        	
        		if (i%2 == 0) {
        			tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + xuhao1 + "</td>";
        			xuhao1=xuhao1+1;
        		} else {
        			tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + xuhao2 + "</td>";
                    xuhao2=xuhao2+1;
        		}
        		/* tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;'>"
                + rows[i]['materType'] + "</td>"; */
                tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;'>"
                + rows[i]['ordMaterName'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>"
                + rows[i]['ordMaterWeightReal'] + "</td>";
                tableStr = tableStr
                + "<td align='center' style='border-style:solid;border-width:1px;'>"
                + rows[i]['unit'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                + rows[i]['ordMaterValueRealUnit'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                + rows[i]['ordMaterValueReal'] + "</td>";
        	
            if(i%2!=0){
                tableStr = tableStr + "</tr>";
            }
            if(i%2==0 && rows.length == i+1){
            	 tableStr = tableStr
                 + "<td  colspan='6' align='right' style='border-style:solid;border-width:1px;'></td>";
            	tableStr = tableStr + "</tr>";
            }
            materValueAllList = decimal(accAdd(materValueAllList,rows[i]['ordMaterValueReal']), 2);
            
        }
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='10' align='left' style='border-style:solid;border-width:1px;'>送货人签字：____________ 收货人签字：____________ </td>";
        tableStr = tableStr
                + "<td colspan='1' align='right' style='border-style:solid;border-width:1px;border-right-width:0px;'>总计:</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;border-left-width:0px;'>￥"
                + materValueAllList + "</td>";
        tableStr = tableStr + "</tr>";
        tableStr = tableStr + "</table>";
        
        return tableStr;
    }
    
    function getPrnStrForWujing1new() {
        var xuhao1,xuhao2;
        var rows = $('#listDisplay').datagrid('getRows');
        xuhao1=1;
        if(30%2==0){
            xuhao2=30/2+1;
        }else{
            xuhao2=Math.round(30/2)+1;
        }
        
        var tableStr;
        tableStr = "<table  style='border-collapse: collapse; border: 2px solid black;'>"
        	//设置公司标题
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td colspan='12' align='center' style='font-size:22px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-bottom-width: 0px;'>"
                    + document.getElementById('supName').value + "送货单</td>";

            tableStr = tableStr + "</tr>";
            
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td colspan='6' align='left' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-top-width: 0px;'>收货单位："+rows[0]['ordCustName']+"</td>"
                    + "<td colspan='3' align='right' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-left-width:0px;border-top-width: 0px;'>订单号：${ordId }</td>"
                    + "<td colspan='3' align='right' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-left-width:0px;border-top-width: 0px;'>送货日期:"
                    + rows[0]['ordDate']; + "</td>";
            tableStr = tableStr + "</tr>";
        	//设置列表属性
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:4%'>号</td>";
            /* tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:9%'>种类</td>"; */
            tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:12%'>材料名</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:5%'>数量</td>";
            tableStr = tableStr
                    + "<td align='center' style='font-size:14px;border-style:solid;border-width:1px;width:6%'>单位</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:7%'>单价</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:8%'>合计</td>";
            tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:4%'>号</td>";
            /* tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:9%'>种类</td>"; */
            tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:12%'>材料名</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:5%'>数量</td>";
            tableStr = tableStr
                    + "<td align='center' style='font-size:14px;border-style:solid;border-width:1px;width:6%'>单位</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:7%'>单价</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:8%'>合计</td>";
            tableStr = tableStr + "</tr>";
        for (var i = 0; i < 30; i++) {
            
            if(i%2==0){
                tableStr = tableStr + "<tr>";
            }
            
                if (i%2 == 0) {
                    tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + xuhao1 + "</td>";
                    xuhao1=xuhao1+1;
                } else {
                    tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + xuhao2 + "</td>";
                    xuhao2=xuhao2+1;
                }
                /* tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;'>"
                + rows[i]['materType'] + "</td>"; */
                tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;'>"
                + rows[i]['ordMaterName'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>"
                + rows[i]['ordMaterWeightReal'] + "</td>";
                tableStr = tableStr
                + "<td align='center' style='border-style:solid;border-width:1px;'>"
                + rows[i]['unit'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                + rows[i]['ordMaterValueRealUnit'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                + rows[i]['ordMaterValueReal'] + "</td>";
            
            if(i%2!=0){
                tableStr = tableStr + "</tr>";
            }
            
        }
        tableStr = tableStr + "</table>";
        return tableStr;
    }
    
    function getPrnStrForWujing2new() {
        var xuhao1,xuhao2;
        var rows = $('#listDisplay').datagrid('getRows');
        xuhao1=1;
        if((rows.length-30)%2==0){
            xuhao2=(rows.length-30)/2+1;
        }else{
            xuhao2=Math.round((rows.length-30)/2)+1;
        }
        
        var tableStr;
        tableStr = "<table  style='border-collapse: collapse; border: 2px solid black;'>"
        	//设置公司标题
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td colspan='12' align='center' style='font-size:22px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-bottom-width: 0px;'>"
                    + document.getElementById('supName').value + "送货单</td>";

            tableStr = tableStr + "</tr>";
            
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td colspan='6' align='left' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-top-width: 0px;'>收货单位："+rows[0]['ordCustName']+"</td>"
                    + "<td colspan='3' align='right' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-right-width:0px;border-left-width:0px;border-top-width: 0px;'>订单号：${ordId }</td>"
                    + "<td colspan='3' align='right' style='font-size:15px;border-style:solid;border-width:2px;height:30px;border-left-width:0px;border-top-width: 0px;'>送货日期:"
                    + rows[0]['ordDate']; + "</td>";
            tableStr = tableStr + "</tr>";
            //设置列表属性
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:4%'>号</td>";
            /* tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:9%'>种类</td>"; */
            tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:12%'>材料名</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:5%'>数量</td>";
            tableStr = tableStr
                    + "<td align='center' style='font-size:14px;border-style:solid;border-width:1px;width:6%'>单位</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:7%'>单价</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:8%'>合计</td>";
            tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:4%'>号</td>";
           /*  tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:9%'>种类</td>"; */
            tableStr = tableStr
                    + "<td style='font-size:14px;border-style:solid;border-width:1px;width:12%'>材料名</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:5%'>数量</td>";
            tableStr = tableStr
                    + "<td align='center' style='font-size:14px;border-style:solid;border-width:1px;width:6%'>单位</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:7%'>单价</td>";
            tableStr = tableStr
                    + "<td align='right' style='font-size:14px;border-style:solid;border-width:1px;width:8%'>合计</td>";
            tableStr = tableStr + "</tr>";
        for (var i = 30; i < rows.length; i++) {
            if(i%2==0){
                tableStr = tableStr + "<tr>";
            }
                if (i%2 == 0) {
                    tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + xuhao1 + "</td>";
                    xuhao1=xuhao1+1;
                } else {
                    tableStr = tableStr
                    + "<td style='border-style:solid;border-width:1px;'>"
                    + xuhao2 + "</td>";
                    xuhao2=xuhao2+1;
                }
                /* tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;'>"
                + rows[i]['materType'] + "</td>"; */
                tableStr = tableStr
                + "<td style='font-size:14px;border-style:solid;border-width:1px;'>"
                + rows[i]['ordMaterName'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>"
                + rows[i]['ordMaterWeightReal'] + "</td>";
                tableStr = tableStr
                + "<td align='center' style='border-style:solid;border-width:1px;'>"
                + rows[i]['unit'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                + rows[i]['ordMaterValueRealUnit'] + "</td>";
                tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;'>￥"
                + rows[i]['ordMaterValueReal'] + "</td>";
            
                if(i%2!=0){
                    tableStr = tableStr + "</tr>";
                }
                if(i%2==0 && rows.length == i+1){
                     tableStr = tableStr
                     + "<td  colspan='6' align='right' style='border-style:solid;border-width:1px;'></td>";
                    tableStr = tableStr + "</tr>";
                }
            
        }
        var materValueAllListnew = 0;
        for (var i = 0; i < rows.length; i++) {
        	materValueAllListnew = decimal(accAdd(materValueAllListnew,rows[i]['ordMaterValueReal']), 2);
        }
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='10' align='left' style='border-style:solid;border-width:1px;'>送货人签字：____________ 收货人签字：____________ </td>";
        tableStr = tableStr
                + "<td colspan='1' align='right' style='border-style:solid;border-width:1px;border-right-width:0px;'>总计:</td>";
        tableStr = tableStr
                + "<td align='right' style='border-style:solid;border-width:1px;border-left-width:0px;'>￥"
                + materValueAllListnew + "</td>";
        tableStr = tableStr + "</tr>";
        tableStr = tableStr + "</table>";
        
        return tableStr;
    }
    
    //校验价格合理性（根据最后一次送货价钱）
    function checkValue(){
    	var rows = $('#listDisplay').datagrid('getSelections');
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
            for (var i = 0; i < rows.length; i++) {
               var rowIndex = $('#listDisplay').datagrid('getRowIndex',rows[i]['ordSupMaterId']);
               $('#listDisplay').datagrid('endEdit', rowIndex);
               var colour = checkValueAjax();
               $('#listDisplay').datagrid('refreshRow', i);
               //$('#listDisplay').datagrid('beginEdit', rowIndex);
            }
        }
    }
    function checkValueAjax(){
    	$.ajax({type:'post',url:"<c:url value='/mater/checkValueReasonableness .do'/>"+"?"+str,dataType:"json",//设置查询参数及提交路径
            success:function(data){
                if(data.success){
                }else{
                    $.messager.alert("提示", data.msg, 'warning');
                }
            },
            error:function(){
            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });
    }
    //导入数量
    function updateMaterWeightAndValue(){
    	var rows = $('#listDisplay').datagrid('getSelections');
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
        	//生成json数据
            var turnoverList = new Array();
            var jsonFater;

            for (var i = 0; i < rows.length; i++) {
                var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                        rows[i]['ordSupMaterId']);
                $('#listDisplay').datagrid('endEdit', rowIndex);
                
                
                var jsonSun = "{materId:'" + rows[i]['ordMaterId'] + "',materLevel:'"
                        + rows[i]['ordMaterLevel'] + "',materWeight:'"
                        + rows[i]['ordMaterWeightReal'] 
                        + "',materValue:'" + rows[i]['ordMaterValueRealUnit'] 
                        + "',materValueUndressed:'" + rows[i]['ordMaterValueRealCostUnit']
                        + "',date:'"+ rows[i]['ordDate'] + "'}";
                turnoverList.push(jsonSun);
                
            }
            //beginEditList(rows, '#listDisplay', 'ordSupMaterId');

            jsonFater = JSON.stringify(turnoverList);
            $("#materJson").attr("value", jsonFater);
            var form = new FormData();
            //ajax 提交表单数据
            form.append("date", rows[0]['ordDate']); // 可以增加表单数据
            form.append("custId", rows[0]['ordCustId']); // 可以增加表单数据
            form.append("materJson", jsonFater); // 可以增加表单数据
            
            // XMLHttpRequest 对象
            xhr = new XMLHttpRequest();
            xhr.open("post", '<c:url value='/supplier/importSupMaterRealityWeightForWeb.do'/>', true);
            xhr.onload = function(a) {
                $.messager.alert('系统提示', '修改成功', 'info', function() {
                    $('#'+listDisplayEId).datagrid('reload');
                    $('#'+listDisplayEId).datagrid('clearSelections');
                });
            };
            xhr.send(form);
        }
    }
    
    function importSupMaterWeightForWeb(){
    	var rows = $('#listDisplay').datagrid('getSelections');
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
            //生成json数据
            var turnoverList = new Array();
            var jsonFater;

            for (var i = 0; i < rows.length; i++) {
                var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                        rows[i]['ordSupMaterId']);
                $('#listDisplay').datagrid('endEdit', rowIndex);
                
                
                var jsonSun = "{materId:'" + rows[i]['ordMaterId'] + "',materLevel:'"
                        + rows[i]['ordMaterLevel'] + "',materWeight:'"
                        + rows[i]['ordMaterWeight'] 
                        + "',ordId:'" + rows[i]['ordId'] 
                        + "',materValueUndressed:'" + rows[i]['ordMaterValueRealCostUnit']
                        + "',date:'"+ rows[i]['ordDate'] + "'}";
                turnoverList.push(jsonSun);
                
            }
            //beginEditList(rows, '#listDisplay', 'ordSupMaterId');

            jsonFater = JSON.stringify(turnoverList);
            $("#materJson").attr("value", jsonFater);
            var form = new FormData();
            //ajax 提交表单数据
            form.append("date", rows[0]['ordDate']); // 可以增加表单数据
            form.append("custId", rows[0]['ordCustId']); // 可以增加表单数据

            form.append("materJson", jsonFater); // 可以增加表单数据
            // XMLHttpRequest 对象
            xhr = new XMLHttpRequest();
            xhr.open("post", '<c:url value='/supplier/importSupMaterWeightForWeb.do'/>', true);
            xhr.onload = function(a) {
            	updateMaterWeightAndValue();
            }; 
            xhr.send(form);
        }
    }
    
    function checkMaterSale(materId,materValue){
        var flag ;

        var str = "materId="+materId+"&materValue="+materValue; 
        $.ajax({
            type:'post',
            async: false, 
            url:"<c:url value='/materCheck/checkMaterSale.do'/>"+"?"+str,dataType:"json",//设置查询参数及提交路径
            success:function(data){
                if(data.success){
                    flag = true;
                }else{
                    flag = false;
                    $('#listDisplay').datagrid('loaded'); 

                    $.messager.alert("提示", data.msg, 'warning');
                }
            },
            error:function(){
            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });
        return flag;
    };
    //检验单位转换
    function checkMaterUnitChange(materId){
        var flag ;
        var str = "materId="+materId; 
        $.ajax({
            type:'post',
            async: false, 
            url:"<c:url value='/materCheck/checkMaterUnitChange.do'/>"+"?"+str,dataType:"json",//设置查询参数及提交路径
            success:function(data){
                if(data.success){
                    flag = true;
                }else{
                    flag = false;
                    $('#listDisplay').datagrid('loaded'); 

                    $.messager.alert("提示", data.msg, 'warning');
                }
            },
            error:function(){
            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });
        return flag;
    };
    
    function unitChange(){
         //校验
    	var rows = $('#listDisplay').datagrid('getSelections');
        if(rows.length != 1){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
        	if(checkUnitMater(rows[0]['ordMaterId'])){
        		//打开div
        		document.getElementById('ordId').value = rows[0]['ordId'];
                document.getElementById('auxiliaryMaterId').value = rows[0]['ordMaterId'];
                document.getElementById('ordCustId').value = rows[0]['ordCustId'];
                document.getElementById('ordMaterLevel').value = rows[0]['ordMaterLevel'];
        		
                var Allwidth = '100%';
                var Allheight = '100%';
                document.getElementById('unitDiv').style.display = '';
                Loading.Show({
                    width : Allwidth,
                    height : Allheight
                });
        	}else{
                $.messager.alert('提示','所选材料不需要转换！','info');
                return;
        	}
        }
    }
    function checkUnitMater(materId){
    	var flag ;
        var str = "materId="+materId; 
        $.ajax({
            type:'post',
            async: false, 
            url:"<c:url value='/materUnit/getHostMaterUnit.do'/>"+"?"+str,dataType:"json",
            success:function(data){
                if(data.success){
                    flag = true;
                    document.getElementById('materId').value = data.materPo.materId;
                    document.getElementById('materName').value = data.materPo.materName;
                    document.getElementById('unit').value = data.materPo.unit;
                    document.getElementById('specifications').value = data.materPo.specifications;
                    document.getElementById('ordMaterWeightReal').value = 0;
                }else{
                    flag = false;
                }
            },
            error:function(){
            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });
        return flag;
    }
    
    var xhrUnitChangeBatch;
    function unitChangeBatch( ) {

        var ordId = "${ordId }";

        var form = new FormData();
        form.append("ordId", ordId); // 可以增加表单数据
        xhrUnitChangeBatch = new XMLHttpRequest();
        xhrUnitChangeBatch.onreadystatechange = unitChangeBatch_return;
        xhrUnitChangeBatch.open(
                        "post",
                        '<c:url value='/order/unitMaterChangeBatch.do'/>',
                        true);
        xhrUnitChangeBatch.send(form);
    }
    function unitChangeBatch_return() {
        if (xhrUnitChangeBatch.readyState == 4) {// 4 = "loaded"

            if (xhrUnitChangeBatch.status == 200) {// 200 = OK
                var data;
                data = xhrUnitChangeBatch.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
               if(data.success){
                   $.messager.alert("提示", "成功转换所有材料！", 'info');
                   $('#listDisplay').datagrid('reload');
               }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    
    function xhrDelete_return() {
        if (xhrDelete.readyState == 4) {// 4 = "loaded"

            if (xhrDelete.status == 200) {// 200 = OK
                var data;
                data = xhrDelete.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
               if(data.success){
                   $.messager.alert("提示", "操作成功！", 'info');
                   $('#listDisplay').datagrid('clearSelections');

                   $('#listDisplay').datagrid('reload');
               }else{
                   $.messager.alert("提示", data.msg, 'info');
               }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    
    var initShowMsgLeft2Flag=true;
    function showMsgLeft2() {
        $('#left2').listbox({
            data : dataLeft,
            height : 300,
            width : 400,
            dndscope : 'demo',
            dnd : false,
            multiselect : true,
            selectchange : function(data) {
                if (data && data.length > 0) {
                    $('#btnRight').attr('disabled', false);
                } else {
                    $('#btnRight').attr('disabled', true);
                }
            }
        });
        var data = [ {
            value : 10,
            text : 'think8848'
        }, {
            value : 20,
            text : 'aCloud'
        }, {
            value : 21,
            text : 'aaaaa'
        }, {
            value : 36,
            text : 'qqqqq'
        } ];
        $('#right2').listbox({
            // data: data,
            height : 300,
            width : 400,
            dndscope : 'demo',
            dnd : true,
            multiselect : true
        });
        $('#btnRightAll2').click(function() {
            var left = $('#left2').listbox();
            var items = left.getDatas();
            left.clear();
            $('#right2').listbox().addRange(items);
        });
        $('#btnLeftAll2').click(function() {
            var right = $('#right2').listbox();
            var items = right.getDatas();
            right.clear();
            $('#left2').listbox().addRange(items);
        });
        $('#btnRight2').click(function() {
            var left = $('#left2').listbox();
            var items = left.getSelected();
            left.removeRange(items);
            $('#right2').listbox().addRange(items);
        });
        $('#btnLeft2').click(function() {
            var right = $('#right2').listbox();
            var items = right.getSelected();
            right.removeRange(items);
            $('#left2').listbox().addRange(items);
        });
        $('#btnRemove2').click(function() {
            $('#right2').listbox().removeRange([ {
                value : 2
            }, {
                value : 26
            } ]);
        });
        $('#btnSelect2').click(function() {
            var selected = $('#right2').listbox().getSelected();
            var msg = 'Selected count is: ' + selected.length;
            if (selected.length > 0) {
                msg += ', The first item text is: ' + selected[0].text;
            }
            msg += '.';
            alert(msg);
        });
        $('#btnGetItems2').click(function() {
            var selected = $('#right2').listbox('getDatas');
            alert('Items count is: ' + selected.length);
        });
        $('#btnSetSelection2').click(function() {
            $('#left2').listbox('setSelection', 1);
        });
        $('#select2').click(function() {
            Loading.Hide();
            document.getElementById('zzy2').style.display = 'none';
            
            var right = $('#right2').listbox();
            var items;
            items = right.getDatas();
            if (items.length == 1) {
                
                for ( var e in items) {
                	//先判断是否已有列表中已经存在要改变的材料
                	var rows = $('#listDisplay').datagrid('getRows');
                	for (var i = 0; i < rows.length; i++) {
                		if(rows[i]['ordMaterId'] == items[e].value ){
                			alert("列别已经存在转变后的材料！请直接删除所选材料！");
                			return ;
                		}
                    } 
                    mater_change(items[e].value);
                } 
            }else{
                alert("只能选取一个材料！");
                return;
            }
            var itemsr = right.getDatas();
            right.removeRange(itemsr);

        });
        $('#noselect2').click(function() {
            Loading.Hide();
            document.getElementById('zzy2').style.display = 'none';
        });
    }
    //改变材料
    var xhr_change;

    function mater_change( materId) {
    	
    	var userList = new Array(); 
        var jsonFater;
            var jsonSun = "{materId:'"+materId+"',date:'"+"${tOrderSupplierPo.ordDate }"+"',materValue:'"+0+"',materValueCost:'"+0+"',supId:'${supId }',materNum:'"+0+"',materLevel:'"+1+"'}";
            userList.push(jsonSun);
        jsonFater = JSON.stringify(userList);
        var form = new FormData();
        form.append("materId", materId); // 可以增加表单数据
        form.append("orderDate", "${tOrderSupplierPo.ordDate }"); // 可以增加表单数据
        form.append("ordId", "${tOrderSupplierPo.ordId }"); // 可以增加表单数据
        form.append("ordCustId", "${tOrderSupplierPo.ordCustId }"); // 可以增加表单数据
        form.append("materdategridList", jsonFater); // 可以增加表单数据




        xhr_change = new XMLHttpRequest();
        xhr_change.onreadystatechange = mater_ChangeRT;
        // xhr.setRequestHeader("Accept", "text/plain")
        xhr_change.open(
                        "post",
                        '<c:url value='/orderSup/commitMaterOrderForUpdate.do'/>',
                        true);
        xhr_change.send(form);
    }
    function mater_ChangeRT() {
        if (xhr_change.readyState == 4) {// 4 = "loaded"

            if (xhr_change.status == 200) {// 200 = OK
                var data;
                data = xhr_change.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                if(data.success){
                    var row = $('#listDisplay').datagrid('getSelections');      
                	deleteMater(row);
                }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    
    
  //附属材料查询模块
    var xhr2;
    function searchInfoForShowCust2() {

        var materId = document.getElementById("materIdForSearch2").value;
        if (materId == '') {
            materId = 0;
        }

        var form = new FormData();
        form.append("materId", materId); // 可以增加表单数据
        form.append("materName", document.getElementById("materName2").value); // 可以增加表单数据
        xhr2 = new XMLHttpRequest();
        xhr2.onreadystatechange = state_ChangeT;
        // xhr.setRequestHeader("Accept", "text/plain")
        xhr2
                .open(
                        "post",
                        '<c:url value='/supplierDistribute/checkSupplierDistributeForGather.do'/>',
                        true);
        xhr2.send(form);
    }
    function state_ChangeT() {
        if (xhr2.readyState == 4) {// 4 = "loaded"

            if (xhr2.status == 200) {// 200 = OK
                var data;
                data = xhr2.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                var a = data.stringJson;
                if (typeof (dataLeft) == 'string' && dataLeft != '') {
                    a = JSON.parse(dataLeft);
                }
                $('#left2').listbox().reload({
                    data : a,
                    ajaxsettings : {
                        data : {
                            id : 'a'
                        }
                    }
                });
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    var xhr_addQuotation;
    function addQuotation() {
    	var rows = $('#listDisplay').datagrid('getSelections');
        if(rows.length != 1){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
            var form = new FormData();
            form.append("shopId", rows[0]['ordCustId']); // 可以增加表单数据
            form.append("materId", rows[0]['ordMaterId']); // 可以增加表单数据
            form.append("materValue", rows[0]['ordMaterValueRealUnit']); // 可以增加表单数据
            xhr_addQuotation = new XMLHttpRequest();
            xhr_addQuotation.onreadystatechange = return_addQuotation;
            // xhr.setRequestHeader("Accept", "text/plain")
            xhr_addQuotation.open(
                            "post",
                            '<c:url value='/quotationCompany/addQuotationMaterByShopIdMaterIdForSup.do'/>',
                            true);
            xhr_addQuotation.send(form);
        }
        
    }
    function return_addQuotation() {
        if (xhr_addQuotation.readyState == 4) {// 4 = "loaded"

            if (xhr_addQuotation.status == 200) {// 200 = OK
                var data;
                data = xhr_addQuotation.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                if(data.success){
                	alert("成功！");
                }else{
                    alert(data.msg);
                }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    
</script>
</head>

<body>
    <form id="AddFoodForm" name="AddFoodForm" method="post">
		<table cellpadding="5">
			      <tr>
                    <td>
				        <input class="easyui-validatebox" type="hidden" name="ordId" required="true" validType="length[1,30]" value="${ordId }"/>
				        <input class="easyui-validatebox" type="hidden" name="materdategridList"  />
				        <input class="easyui-validatebox" type="hidden" id="ordSupId" name="ordSupId" value="${supId }" />
				        <td><input class="easyui-validatebox" editable="false" id="supName" name="supName" type="hidden"></input></td>
 			            <td><input class="easyui-validatebox" editable="false" id="unitFlag" name="unitFlag"  type="hidden" value=="${shopPo.unitFlag }"></input></td>
 			        </td>
                  </tr>
        </table>
    </form>

	<table id="listDisplay" title="材料订单列表" singleSelect=false
		iconCls="icon-list" idField="ordSupMaterId"
		url="<c:url value="/order/findcustMaterDetailed.do?oid=${ordId }&supId=${supId }"/>"
		style="width: 100%;" loadMsg="请稍候......"
		pagination="false" pageSize="20"
		pageList="[10,20,30,40,50,100,150]" sortName="roleId"
		rownumbers="true" sortOrder="asc" showFooter="true">
		<thead>
				<tr>
				    <th field="id" width="25" align="center"  checkbox="true">
					</th> 
					<th field="ordSupMaterId" width="80"  sortable="true" hidden="true">
						ID
					</th>
				    <th field="ordId" width="60"  sortable="true" styler="cellStylerLeaveMessage">
						订单ID
					</th>	
 					<th field="ordCustId" width="55" sortable="true" hidden ="true" hidden ='true'>
						客户ID
					</th>
					<th field="ordCustName" width="70" sortable="true" styler="cellStylerLeaveMessage">
						客户名
					</th>
					<th field="ordSupId" width="60" sortable="true" hidden ="true" styler="cellStylerLeaveMessage">
						供货商ID
					</th>	
					<th field="ordSupName" width="80" sortable="true" hidden="true" styler="cellStylerLeaveMessage" >
						供货商名
					</th>	
					<th field="ordMaterId" width="60" sortable="true" styler="cellStylerLeaveMessage" >
						材料id
					</th>
					<th field="ordMaterName" width="80"  sortable="true" styler="cellStylerLeaveMessage">
						材料名
					</th>
					<th field="materType" width="80"  sortable="true" styler="cellStylerLeaveMessage">种类
                    </th>
					<th field="ordMaterLevel" width="50"  sortable="true"  formatter="formatFoodType" hidden="true" >
						品级
					</th>
                    <th field="brands" width="60" sortable="true" styler="cellStylerLeaveMessage">品牌
                    </th>
                    <th field="specifications" width="60" sortable="true" styler="cellStylerLeaveMessage">规格
                    </th>
                    <th field="unit" width="60"  sortable="true"styler="cellStylerLeaveMessage" >单位
                    </th>   
					<th field="ordMaterWeight" width="60"  sortable="true"  styler="cellStylerLeaveMessage"  editor="text" >
						需求数量
					</th>
					<!-- <th field="ordMaterValue" width="90"  sortable="true" hidden="true" styler="cellStylerLeaveMessage">
						估算材料价格
					</th> -->
					<!-- <th field="storeWeight" width="60"  sortable="true" hidden='true' styler="cellStylerLeaveMessage">
						材料库存
					</th> -->	
					<th field="ordMaterWeightReal" width="60"  sortable="true" styler="cellStylerTrue" editor="text">
						实际数量
					</th>	
					<th field="ordMaterValueRealCostUnit" width="70"  sortable="true"styler="cellStylerLeaveMessage" editor="text">
                                                进货单价
                    </th>
                    <th field="ordMaterValueRealCost" width="70"  sortable="true"styler="cellStylerLeaveMessage" >
                                                进货总价
                    </th>
                    <th field="ordMaterValueRealUnit" width="70"  sortable="true" styler="cellStyler"editor="text">
                                                实际单价
                    </th>
					<th field="ordMaterValueReal" width="70"  sortable="true"styler="cellStylerLeaveMessage" >
						实际总价
					</th>
					<!-- <th field="returnGoods" width="60"  sortable="true" formatter="formaterReturnGoods" styler="cellStyler">退货标记
                    </th> -->
					<!-- <th field="unusualRemark" width="100"  sortable="true" >异常说明
                    </th> -->
                    <th field="leaveMessage" width="80" sortable="true"   styler="cellStylerLeaveMessage">留言</th>
                    <th field="submitOrdTime" width="100" sortable="true"  >提交订单时间
                    </th>
                    <th field="periodValueFlag" width="80" sortable="true"   hidden="true" >周期报价</th>
                    <th field="ordDate" width="100" sortable="true"  hidden="true">订单时间
                    </th>
 				</tr>
		</thead>
	</table>
	<object id="LODOP_OB"
        classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
    </object>
     <!--右侧菜单栏购物车样式-->
<div class="fixedBox">
  <ul class="fixedBoxList">
    <!-- <li class="fixeBoxLi user"><a href="User.html"> <span class="fixeBoxSpan iconfont icon-yonghu"></span> <strong>用户</strong></a> </li>
    <li class="fixeBoxLi cart_bd" style="display:block;" id="cartboxs">
        <p class="good_cart">0</p>
            <span class="fixeBoxSpan iconfont icon-cart"></span> <strong>购物车</strong>
            <div class="cartBox">
            <div class="bjfff"></div><div class="message">购物车内暂无商品，赶紧选购吧</div>    </div></li> -->

    <li class="fixeBoxLi Home"> <a onclick="unitChange();"> <span class="fixeBoxSpan iconfont  icon-shoucang"></span> <strong>单位改变</strong> </a> </li>
    <li class="fixeBoxLi Home"> <a onclick="unitChangeBatch();"> <span class="fixeBoxSpan iconfont  icon-shoucang"></span> <strong>批量单位改变</strong> </a> </li>
    <li class="fixeBoxLi Home"> <a onclick="addQuotation();"> <span class="fixeBoxSpan iconfont  icon-shoucang"></span> <strong>加入周期报价</strong> </a> </li>
    <li class="fixeBoxLi Home"> <a onclick="importSupMaterWeightForWeb();"> <span class="fixeBoxSpan iconfont  icon-shoucang"></span> <strong>改变需求数量</strong> </a> </li>
    <!-- <li class="fixeBoxLi BackToTop"> <span class="fixeBoxSpan iconfont icon-top"></span> <strong>返回顶部</strong> </li> -->
  </ul>
</div>

<div  id="unitDiv" style='position: absolute; left: 40px; top: 40px; z-index: 101; border-radius: 10px; height: 300px;width: 550px;'>
    <div style="height: auto; width:100%;background: #fafafa; padding: 5px;" class="easyui-panel" title="单位转换" iconCls="icon-search" collapsible="true" minimizable="false" maximizable="false" closable="false">
        <form id="unitChangeForm" name="searchFormForShowCust" method="post" accept-charset="UTF-8">
        <table >
            <tr>
                <td>材料名称：</td>
                <td><input class="easyui-validatebox" id="materName" editable="false" name="materName"  readOnly='true'></input></td>
                <td><input class="easyui-validatebox" id="materId" editable="false" name="materId" hidden='true' readOnly='true'></input></td>
                <td><input class="easyui-validatebox" id="auxiliaryMaterId" editable="false" name="auxiliaryMaterId" hidden='true' readOnly='true'></input></td>
                <td><input class="easyui-validatebox" id="ordId" editable="false" name="ordId" hidden='true' readOnly='true'></input></td>
                <td><input class="easyui-validatebox" id="ordCustId" editable="false" name="ordCustId" hidden='true' readOnly='true'></input></td>
                <td><input class="easyui-validatebox" id="ordMaterLevel" editable="false" name="ordMaterLevel" hidden='true' readOnly='true'></input></td>
                
            </tr>
            <tr>
                <td>规格：</td>
                <td><input class="easyui-validatebox" id="specifications" editable="false" name="specifications"  readOnly='true'></input></td>
            </tr>
            <tr>
                <td>单位：</td>
                <td><input class="easyui-validatebox" id="unit" editable="false" name="unit"  readOnly='true'></input></td>
            </tr>
            <tr>
                <td>单位数量：</td>
                <td><input class="easyui-validatebox" id="ordMaterWeightReal" editable="false" name="ordMaterWeightReal"></input></td>
            </tr>
            <tr>
               
                <td><input type="button" value="取消" id="noselectMaterUnit"/></td>
                <td><input type="button" value="转换" id="selectMaterUnit" /></td>
            </tr>
        </table>
        </form>
    </div>
</div>
<div style='position: absolute; left: 40px; top: 40px; z-index: 101; background-color: #FFFFFF; border-radius: 10px; width: 1000px;'id="zzy2">
        <table align="center">
            <tr>
                <td colspan="3">
                    <form id="searchFormForShowCust" name="searchFormForShowCust"
                        method="post" accept-charset="UTF-8">
                        <div
                            style="height: auto; width: 800px; background: #fafafa; padding: 5px;"
                            class="easyui-panel" title="查询" iconCls="icon-search"
                            collapsible="true" minimizable="false" maximizable="false"
                            closable="false">
                            <table>
                                <tr>
                                    <td>材料id:</td>
                                    <td><input class="easyui-numberbox" name="materIdForSearch2"
                                        id="materIdForSearch2" /></td>
                                    <td>材料名称:</td>
                                    <td><input class="easyui-validatebox" name="materName2"
                                        id="materName2" /></td>
                                    <td><a href="#" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-search'" style="width: 60px"
                                        onclick="searchInfoForShowCust2()">查询</a></td>
                                    <td><input type="hidden" name="materdategridList"
                                        id="materdategridList" /></td>

                                </tr>
                            </table>
                        </div>
                    </form>
                </td>
            </tr>
            <tr>
                <td>
                    <ul id="left2">
                    </ul>
                </td>
                <td><input type="button" value="&gt;&gt;" id="btnRightAll2"style="width: 50px;" /><br />
                    <input type="button" value="&gt;" id="btnRight2" style="width: 50px;" /><br /> 
                    <input type="button" value="&lt;" id="btnLeft2" style="width: 50px;" /><br /> 
                    <input type="button" value="&lt;&lt;" id="btnLeftAll2" style="width: 50px;" />
                </td>
                <td>
                    <ul id="right2">
                    </ul>
                </td>
            </tr>
        </table>
        <table align="center">
            <tr>
                <!--  
                <td><input type="button" value="Add Item" id="btnAdd" /></td>
                <td><input type="button" value="Remove Item" id="btnRemove" /></td>
                <td><input type="button" value="Get Select" id="btnSelect" /></td>
                <td><input type="button" value="Get Items" id="btnGetItems" /></td>
                <td><input type="button" value="SetSelection (value equal to '1')" id="btnSetSelection" /></td>
                <td><input type="button" value="Reload" id="btnReload" /></td>
                -->
                <td><input type="button" value="取消" id="noselect2" /></td>
                <td width="200px"></td>
                <td><input type="button" value="选择" id="select2" /></td>

            </tr>
        </table>
</div>
</body>

</html>